package ru.spb.osll.myfit.userchart;

import ru.spb.osll.myfit.common.chart.ChartCurve;
import ru.spb.osll.myfit.common.chart.ChartPoint;
import ru.spb.osll.myfit.server.chart.*;
import ru.spb.osll.myfit.chart.AbstractChartsBuilder;
import ru.spb.osll.myfit.util.parser.ILogParser;
import ru.spb.osll.myfit.util.parser.IResultSection;

import java.io.IOException;
import java.util.List;

/**
 * User: Artem Bukhonov
 * Email: nerzhulart@gmail.com
 * Date: 10.11.11
 * Time: 17:48
 */
public class SquareChartsBuilder extends AbstractChartsBuilder {

  @Override
  protected void generateCharts(List<? extends IResultSection> results) throws IOException {
    ChartRenderData renderData = new ChartRenderData("Square");
    renderData.setHorizontalLabel("h units");
    renderData.setVerticalLabel("v units");
    ChartCurve curve = new ChartCurve("Square");
    IResultSection rs = results.get(0);
    for (String[] row : rs.getRows()) {
      int x = Integer.valueOf(row[0]);
      int y = Integer.valueOf(row[1]);
      curve.getPoints().add(new ChartPoint(x, y));
    }
    renderData.getCurves().add(curve);
    addChart(renderData);
  }

  @Override
  protected ILogParser getLogParser() {
    return new SquareLogParser();
  }
}
